{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "GLFQA"

// By ArtemQa146

const
    Golf_man = 31@
    golf_ball = 30@
    find = 29@
    progress = 28@
    coords_x = 24@
    coords_y = 23@
    coords_z = 22@
    angle_1 = 21@
    left = 1
    right = 2
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0087: angle_1 = 3@ // (float)

    
        repeat
        wait 0
        04ED: load_animation  "PedEventsMod"
        until 04EE:   animation "PedEventsMod" loaded
        
        
        if 0E4D: random_percent 50
        then 0@ = 36
        else 0@ = 37
        end
        model.Load(0@)
        model.Load(3065)
        model.Load(333)
        model.Load(1974)
        if
            not model.Available(0@)
        then
            repeat
            wait 0
            model.Load(0@)
            until model.Available(0@)
        end
        if
            not model.Available(3065)
        then
            repeat
            wait 0
            model.Load(3065)
            until model.Available(3065)
        end
        if
            not model.Available(333)
        then
            repeat
            wait 0
            model.Load(333)
            until model.Available(333)
        end
        if
            not model.Available(1974)
        then
            repeat
            wait 0
            model.Load(1974)
            until model.Available(1974)
        end
        038B: load_requested_models
        
        009A: Golf_man = create_actor_pedtype 21 model 0@ at coords_x coords_y coords_z
        0173: set_actor Golf_man Z_angle_to angle_1
        0E24: fix_char Golf_man ground 1 brightness 1 and_fade_in 0
        01B2: give_actor Golf_man weapon 2 ammo 610 // Load the weapon model before using this

        0812: AS_actor Golf_man perform_animation "Golf_IDle" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
        04C4: store_coords_to 1@ 2@ 3@ from_actor Golf_man with_offset 0.9 0.0 -0.9
        0E01: create_object_no_save 3065 at 1@ 2@ 3@ offset 0 ground 0 to golf_ball
        08D2: object golf_ball scale_model 0.0
        0F03: create_render_object_to_object golf_ball model 1974 offset 0 0 0 rotation 0 0 0 store_to 1@
        0172: 1@ = actor Golf_man Z_angle
        0177: set_object golf_ball Z_angle_to 1@

        model.Destroy(0@)
        model.Destroy(3065)
        model.Destroy(333)
        model.Destroy(1974)
        
        progress = 0
        
        07F7: set_object golf_ball destructible 0

        
        repeat
        wait 0
        if and
            056D:   actor Golf_man defined
            03CA:   object golf_ball exists
        then
        
            080E: get_actor Golf_man ped_event_to 1@
            if or
                0118:   actor Golf_man dead
                051A:   actor Golf_man damaged_by_actor $PLAYER_ACTOR
                not locate_char_distance_to_char $player_actor char Golf_man radius 100.0
                1@ == 49
                1@ == 9
                not $ACTIVE_INTERIOR == 0
            then
                break
            end
            
            080E: get_actor Golf_man ped_event_to 1@
            if or
                1@ == 15
                1@ == 31
                1@ == 59
            then
                break
            end
            
            if
                0457:   player $PLAYER_CHAR aiming_at_actor Golf_man
            then
                0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 1@
                0E89: get_weaponinfo_fire_type 1@ store_to 2@ //     
                if or
                    2@ == 1 //  
                    2@ == 3 //   (  ..)
                then
                    break
                end
            end
        
            if and
                progress == 0
                0EE4: locate_char_distance_to_char $player_actor char Golf_man radius 15.0
            then
                progress = 1
                if
                    0E4D: random_percent 50
                then
                    0615: define_AS_pack_begin 1@
                    0812: AS_actor -1 perform_animation "Golf_hit" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 1 lockY 1 lockF 0 time -1  // versionB
                    0812: AS_actor -1 perform_animation "Golf_celeb" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 1 lockY 1 lockF 0 time -1  // versionB
                    0616: define_AS_pack_end 1@
                    0618: assign_actor Golf_man to_AS_pack 1@
                    061B: remove_references_to_AS_pack 1@
                else
                    0615: define_AS_pack_begin 1@
                    0812: AS_actor -1 perform_animation "Golf_hit" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 1 lockY 1 lockF 0 time -1  // versionB
                    0812: AS_actor -1 perform_animation "Golf_curse" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 1 lockY 1 lockF 0 time -1  // versionB
                    0616: define_AS_pack_end 1@
                    0618: assign_actor Golf_man to_AS_pack 1@
                    061B: remove_references_to_AS_pack 1@
                end
            end
            
            if and
                0611:   actor Golf_man performing_animation "Golf_hit"
                progress == 1
            then
                0613: 1@ = actor Golf_man animation "Golf_hit" time
                if
                    1@ > 0.25
                then
                    0400: store_coords_to 1@ 2@ 3@ from_object golf_ball with_offset 0.0 0.7 0.15
                    0815: put_object golf_ball at 1@ 2@ 3@  and_keep_rotation
                    05A1: set_object golf_ball rotation_velocity_about_an_axis 0.0 10.0 10.0 through_center_of_body
                    progress = 2
                    timera = 0
                end
            end
            
            if and
                timera > 3000
                progress == 2
                8611:   not actor Golf_man performing_animation "Golf_hit"
                8611:   not actor Golf_man performing_animation "Golf_celeb"
                8611:   not actor Golf_man performing_animation "Golf_curse"
            then
                break
            end
        
        else
            break
        end
        until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0
        if
            locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0
        then
            if 056D:   actor Golf_man defined
            then 01C2: remove_references_to_actor Golf_man // Like turning an actor into a random pedestrian
            end
            if 03CA:   object golf_ball exists
            then 01C4: remove_references_to_object golf_ball // This object will now disappear when the player looks away
            end
        else
            if 056D:   actor Golf_man defined
            then 009B: destroy_actor Golf_man
            end
            if 03CA:   object golf_ball exists
            then 0108: destroy_object golf_ball
            end
        end
        04EF: release_animation "PedEventsMod"
        
        repeat
        wait 0
        until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0
        
0A93: terminate_this_custom_script

